#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include<QDebug>
#include<fstream>
#include<iostream>
#include<QShortcut>
#include<QFormLayout>
#include<QButtonGroup>
#include<QLineEdit>
#include<QTimer>
#include<windows.h>
#include<QPushButton>
#include<QToolTip>
#include<QDockWidget>
#include<QDialog>
#include<QPushButton>
#include<QStatusBar>
#include<QToolBar>
#include<QPair>
#include<QCursor>
#include<QSound>
#include<QVector>
#include<QPair>
#include<QMap>
#include<QMessageBox>
#include<QColorDialog>
#include<functional>
#include<QFileDialog>
#include<QFontDialog>
#include<QTimer>
#include<QInputDialog>
#include<QFile>
#include<QFileDevice>
#include<QWaitCondition>
#include<Qpainter>
#include<QPaintEvent>
#include <bits/ios_base.h>
#include"plant.h"
#include"zom.h"
#include"sunshine.h"
#include"sunshine.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
enum{Single_Pea,Sun_Flower,Snow_Pea,Nut,Potato_Mine};
class MainWindow : public QMainWindow
{
    Q_OBJECT
public:

    QVector<QVector<plant*>> Plants;
    QVector<QVector<zom>> Zoms;
    QVector<sunshine> Sunshines;
    QVector<sunshine> Collectshines;
    int life_length=70;
    bool failure=false;
    int sunsum=200;
    int update_fre=75;
    QTimer* timer_update;
    int produce_prepare=10000;    //玩家准备时间(僵尸到来之前)
    bool prepare_finish=false;
    int produce_zom_fre=6500;   //第一阶段僵尸产出速率
    int produce_zom_fre1=3000;  //依次类推僵尸产出速率
    int produce_zom_fre2=2000;
    int produce_zom_fre3=1000;
    int auto_collect_pre=0;
    int auto_collect_fre=5800;
    int produce_zom_pre=0;
    bool select_plant=false;
    bool select_chan=false;
    bool exist_lose=false;
    bool produce_zom_stage1=false;  //难度会不断上升即僵尸产出的速度不断提高(分为3个阶段)
    bool produce_zom_stage2=false;
    bool produce_zom_stage3=false;
    int select_type;
    int cursor_x;
    int cursor_y;
    long long sum_time=0;
    QLabel* label_sun;
    QMediaPlayer sun_media;
    QMediaPlayer* bgm_media;
    QMediaPlayer* zom_com;
    QMediaPlayer* plant_select;
    QMediaPlayer* planted;
    QMediaPlayer* eat_media;
    QMediaPlayer* chan_media;
    QMediaPlayer* erase_media;
    QMediaPlayer* lose_media;
    QSet<int> eat_se;
    int exist_eat=0;
    int eat_fre=500;
    int eat_pre=500;
    QPen pen;

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
public:
    void Init();
    void dragPaint(QPainter* pa,QPixmap& pm);
    void initBackground(QPainter* pa,QPixmap& pm);
    void Paint(QString str,int x,int y,int w,int h,QPainter* pa,QPixmap& pm);
    void update_plant(  QVector<QVector<plant*>>&Plants,QVector<QVector<zom>>& Zoms,QPainter* pa,QPixmap& pm);
    void update_zom( QVector<QVector<zom>>&Zoms, QPainter *pa, QPixmap &pm);
    void update_sun(QVector<sunshine>& Sunshines,QPainter *pa, QPixmap &pm);
    void Zom_Eat_sound();
    void collectsun(QPainter* pa,QPixmap& pm);
    void Auto_Collect_Sun();
    void makezom();
public:
    void mouseMoveEvent(QMouseEvent* me)override;
    void mouseReleaseEvent(QMouseEvent* me)override;
    void paintEvent(QPaintEvent*pe)override;
    void mousePressEvent(QMouseEvent* me)override;


private:
    Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
